<template>
    <div class="calendar-container" style="padding: 10px;margin-top: 20px;">
      <!-- 日期列表 -->
      <div class="date-list">
        <div
          v-for="(day, index) in weekDates"
          :key="index"
          class="date-item"
          :class="{ active: index === innerIndex }"
          @click="selectDay(index, day)"
        >
          <div>
            <div class="weekday">{{ day.weekDay }}</div>
            <div class="date">{{ day.date }}</div>
          </div>
          <div
            class="status"
            :class="{
              subscribed: day.orderType === '1',
              'not-subscribed': day.orderType === '0'
            }"
          >
            {{ day.orderType === '1' ? '已订' : '未订' }}
          </div>
        </div>
      </div>
    </div>
  </template>
  
  <script>
  export default {
    name: 'Calendar',
    props: {
      weekIndex: {
        type: Number,
        default: 0
        },
        weekDatesOBJ: {
            type: Object,
            default:()=>{}
       }
    },
    data() {
      return {
        innerIndex: 0,
        weekDates: this.generateNextWeekDates()
      }
    },
    watch: {
      weekIndex: {
        immediate: true,
        handler(val) {
          this.innerIndex = val
        }
      }
    },
    methods: {
      generateNextWeekDates() {
        const weekDays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
        const today = new Date()
        const nextWeekStart = new Date(today)
        
        // 计算下周一的日期
        const daysToNextMonday = (8 - today.getDay()) % 7
        nextWeekStart.setDate(today.getDate() + daysToNextMonday)
        
        // 生成下周7天的数据
        const dates = []
        for (let i = 0; i < 7; i++) {
          const date = new Date(nextWeekStart)
          date.setDate(nextWeekStart.getDate() + i)
          
          dates.push({
            orderType: '0', // 默认未订
            date: `${date.getMonth() + 1}/${date.getDate()}`,
            fullDate: `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`,
            weekDay: weekDays[date.getDay()],
            dictDataList: null
          })
        }
        
        return dates
      },
      
        selectDay(index, day) {
        console.log('点击日期列表了', index, day)
        if (day.orderType === '1') {
          this.$message('已经订过了~')
          return
        }
        this.innerIndex = index
        this.$emit('cutWeek', { index, day })
      }
    }
  }
  </script>
  
  <style scoped>
  .calendar-container {
    display: flex;
    align-items: center;
    padding: 12px 0;
  }
  
  .date-list {
    width: 100%;
    display: flex;
    justify-content: space-between;
  }
  
  .date-item {
    width: 45px;
    height: 70px;
    background: #fff;
    border-radius: 8px;
    padding: 6px;
    text-align: center;
    font-size: 12px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    color: #323232;
    cursor: pointer;
  }
  
  .date-item.active {
    background: linear-gradient(90deg, #25b982 0%, #1ab57b 100%);
    color: white;
  }
  
  .date-item.active .weekday {
    color: #fff;
  }
  
  .weekday {
    color: #848484;
    margin-top: 4px;
    font-size: 12px;
  }
  
  .date {
    font-weight: bold;
    font-size: 14px;
  }
  
  .status {
    border-radius: 999px;
    font-size: 10px;
    width: 35px;
    height: 16px;
    line-height: 16px;
  }
  
  .status.not-subscribed {
    color: #fff;
    background: #00c777;
  }
  
  .status.subscribed {
    color: #fff;
    background: #b3b3b3;
  }
  
  .date-item.active .status.not-subscribed {
    color: #00c777;
    background: #fff;
  }
  </style>